package com.qufadai.reader.entity;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "t_ticker")
@NamedQueries(value={
		@NamedQuery(name="TickerEntity.findBySource", query="FROM TickerEntity t WHERE t.source = :source ORDER BY t.id DESC"),
		@NamedQuery(name="TickerEntity.findBySourceAndUpdated", query="FROM TickerEntity t WHERE t.source = :source AND t.updated > :updated ORDER BY t.id DESC")})
@NamedNativeQueries(value={
		@NamedNativeQuery(name="TickerEntity.fetchLastBySourceAndCoinType", query = "SELECT limit 0, 1 t.* FROM t_ticker t WHERE t.source = ?1 AND t.coin_type = ?2 ORDER By t.id DESC", resultClass = TickerEntity.class)
})
public class TickerEntity {

	@Id
	@GeneratedValue
	private Long id;

	private BigDecimal last;
	
	private BigDecimal high;
	
	private BigDecimal low;
	
	@Column(name = "AVG_PRICE")
	private BigDecimal avgPrice;
	
	private BigDecimal sell;
	
	private BigDecimal buy;
	
	private Integer source;
	
	private Long updated;
	
	@Column(name = "COIN_TYPE")
	private String coinType;

	public BigDecimal getAvgPrice() {
		return avgPrice;
	}

	public void setAvgPrice(BigDecimal avgPrice) {
		this.avgPrice = avgPrice;
	}

	public String getCoinType() {
		return coinType;
	}

	public void setCoinType(String coinType) {
		this.coinType = coinType;
	}

	public Integer getSource() {
		return source;
	}

	public void setSource(Integer source) {
		this.source = source;
	}

	public Long getUpdated() {
		return updated;
	}

	public void setUpdated(Long updated) {
		this.updated = updated;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public BigDecimal getLast() {
		return last;
	}

	public void setLast(BigDecimal last) {
		this.last = last;
	}

	public BigDecimal getHigh() {
		return high;
	}

	public void setHigh(BigDecimal high) {
		this.high = high;
	}

	public BigDecimal getLow() {
		return low;
	}

	public void setLow(BigDecimal low) {
		this.low = low;
	}

	public BigDecimal getSell() {
		return sell;
	}

	public void setSell(BigDecimal sell) {
		this.sell = sell;
	}

	public BigDecimal getBuy() {
		return buy;
	}

	public void setBuy(BigDecimal buy) {
		this.buy = buy;
	}
}
